class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
       if(head==NULL||head->next==NULL) return head;
        ListNode* h=head,*r=NULL,*p=NULL,*t=h;
        while(h!=NULL){
          p=h->next;
          if(p!=NULL&&h->val==p->val){
            h->next=p->next;
            p=head;
          }
          if(p!=head){
          h=h->next;
          }
        }
        return head;
    }
};
